package cn.wolfcode.rest.controller;

import cn.wolfcode.rest.domain.Employee;
import cn.wolfcode.rest.domain.Salary;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("employees")

public class EmployeeController {
    //获取所有的员工
    @GetMapping()
    public List<Employee> list(){
        ArrayList<Employee> list = new ArrayList<>();
        list.add(new Employee(1L,"李四"));
        list.add(new Employee(2L,"张三"));
        System.out.println("林强是个大傻逼");
        System.out.println("林强是个大傻逼");
        System.out.println("林强是个大傻逼");
        return list;
    }


    //获取某个员工
    @GetMapping("{id}")
    public Employee get(@PathVariable Long id){
        return new Employee(id,"绘梨衣");
    }




    //批量删除员工或删除某个员工
    @DeleteMapping("{id}")
    public void delete(@PathVariable Long[] id){
        System.out.println("删除员工" + Arrays.toString(id));
    }

 /*   //4.获取某个员工某个月的薪资记录
    @GetMapping("{id}/salaries/{date}")//设置后台返回json的数据给前台
    public Salary getSalary(@PathVariable Long id,
                            @PathVariable@DateTimeFormat(pattern = "yyyy-MM") Date date){

      return new Salary(1L,id, BigDecimal.valueOf(10000L),date);
    }*/

    //
    @GetMapping("{employeeId}/salaries/{date}")
    public Salary getSalary1(Salary salary){
        salary.setId(2L);
        salary.setMoney(BigDecimal.valueOf(1000L));
        return salary;
    }

    //ajax请求
    @PostMapping("post")
    //贴上RequestBody就可以接受前台传过来的json数据
    public void post(@RequestBody Employee employee){
        System.out.println("post-----------------------" + employee.toString());
    }


    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable Long id){
        System.out.println("删除-----------------------" + id );
    }



    @PutMapping("put/{id}")
    public void put(@PathVariable Long id){
        System.out.println("put-------------------" + id);
    }



    @PutMapping("putform/{id}")
    public void putForm(@PathVariable Long id){
        System.out.println("put-------------------" + id);
    }

}

